#include<iostream>
#include<queue>
#include<vector>
using namespace std;
const int N = 1e6 + 10;
vector<int> edges[N];
int f[N];
queue<int> q;
int n, m;
int len[N];
int in[N];
int main()
{
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		int x = 0;
		cin >> x;
		cin >> len[x];
		int j = 0;
		while (cin >> j, j)
		{
			in[x]++;
			edges[j].push_back(x);
		}
	}
	for (int i = 1;i <= n;i++)
	{
		if (in[i] == 0)
		{
			q. push(i);
			//千万不要再这里给len，因为咱们这入队后每次出队还会给呢，这会给就重复了
		}
	}
	int ret = 0;
	while (q.size())
	{
		int x = q.front();
		f[x] += len[x];
		ret = max(ret, f[x]);
		q.pop();

		for (auto y : edges[x])
		{
			in[y]--;
			f[y] = max(f[y], f[x]);
			if (in[y] == 0) q.push(y);
		}
		
	}
	cout << ret << endl;
	return 0;
}
